//
// Created by wkm on 2024-04-17.
//

#include "x9time.h"

void x9time::prc_x9time() {
    if (reset) {
        next_result = 0;
        next_done = waiting_task;
        x2_reset = true;
    }

    if (start && done == waiting_task) {
        next_result = input_data;
        next_done = preparing_task;
        x2_reset = false;
    }

    if (done == preparing_task) {
        x2_compute_times.write(3);
        x2_input_data.write(input_data);
        x2_start = true;
        next_done = computing_task;
    }

    if (done == computing_task && x2_done == task_finished) {
        next_done = task_finished;
        next_result = next_result ^ x2_result.read();
    }

    result = next_result;
    done = next_done;
}